/**
 * @author Jason Pratt
 */

package edu.cmu.cs.stage3.alice.authoringtool.util;

public class CustomMouseAdapter extends java.awt.event.MouseAdapter {

 protected double clickDistMargin = 5.0;
 protected long clickTimeMargin = 300;
 protected long multipleClickTimeMargin = 600;

 protected java.awt.Point pressPoint = new java.awt.Point();
 protected long pressTime = 0;
 protected int clickCount = 0;

 public double getClickDistanceMargin () {
  return clickDistMargin;
  }

 public void setClickDistanceMargin (double dist) {
  clickDistMargin = dist;
  }

 public long getClickTimeMargin () {
  return clickTimeMargin;
  }

 public void setClickTimeMargin (long time) {
  clickTimeMargin = time;
  }

 public long getMultipleClickTimeMargin () {
  return multipleClickTimeMargin;
  }

 public void setMultipleClickTimeMargin (long time) {
  multipleClickTimeMargin = time;
  }

 //Rem @Override
 public void mousePressed (java.awt.event.MouseEvent mouseevt) {
String str = ""+mouseevt.getClickCount()+" "+mouseevt.getModifiers();
  long dt = System.currentTimeMillis() - pressTime;
  if (dt > multipleClickTimeMargin) {
   clickCount = 0;
   }
str += " "+clickCount+" em ("+mouseevt.getX()+","+mouseevt.getY()+"): source="+edu.cmu.cs.stage3.util.StrUtilities.getComponentNameTitle(mouseevt.getSource());
System.out.println("CustomMouseAdapter.java: mousePressed: "+str);
  pressPoint.setLocation( mouseevt.getPoint() );
  pressTime = System.currentTimeMillis();
  if (mouseevt.isPopupTrigger()) {
   popupResponse( mouseevt ); // edu.cmu.cs.stage3.alice.authoringtool.viewcontroller.ResponsePrintViewController$MouseListener.popupResponse(...)
  } else {
   mouseDownResponse( mouseevt );
   }
  }

 //Rem @Override
 public void mouseReleased (java.awt.event.MouseEvent mouseevt) {
  if (mouseevt.isPopupTrigger()) {
   popupResponse( mouseevt );
  } else {
   mouseUpResponse( mouseevt );
   }

  double dist = pressPoint.distance( mouseevt.getPoint() );
  long dt = System.currentTimeMillis() - pressTime;
  if ((dist < clickDistMargin) && (dt < clickTimeMargin)) {
   clickCount++;
   if (clickCount == 1) {
    singleClickResponse( mouseevt );
   } else if (clickCount == 2) {
    doubleClickResponse( mouseevt );
   } else if (clickCount == 3) {
    tripleClickResponse( mouseevt );
    }
   }
  }

 protected void singleClickResponse( java.awt.event.MouseEvent mouseevt) {}
 protected void doubleClickResponse( java.awt.event.MouseEvent mouseevt) {}
 protected void tripleClickResponse( java.awt.event.MouseEvent mouseevt) {}
 protected void mouseUpResponse( java.awt.event.MouseEvent mouseevt) {}
 protected void mouseDownResponse( java.awt.event.MouseEvent mouseevt) {}
 protected void popupResponse( java.awt.event.MouseEvent mouseevt) {}

 }
